<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>craftenv.ps1</title>
<meta name="generator" content="KF5::SyntaxHighlighting (PowerShell)"/>
</head><body style="color:#1f1c1b"><pre>
<span style="color:#898887;">&lt;#</span>
<span style="color:#898887;">   Copied from Craft for testing syntax highlighting</span>
<span style="color:#898887;">#&gt;</span>

<span style="color:#bf0303;">@&quot; multi</span>
<span style="color:#bf0303;">   line</span>
<span style="color:#bf0303;">   string</span>
<span style="color:#bf0303;">&quot;@</span>

<span style="color:#898887;">#    this file sets some environment variables that are needed</span>
<span style="color:#898887;">#    for finding programs and libraries etc.</span>
<span style="color:#898887;">#    by Hannah von Reth &lt;vonreth@kde.org&gt;</span>
<span style="color:#898887;">#    you should copy kdesettings.ini to ..\etc\kdesettings.ini</span>
<span style="color:#898887;">#    and adapt it to your needs (see that file for more info)</span>

<span style="color:#898887;">#    this file should contain all path settings - and provide thus an environment</span>
<span style="color:#898887;">#    to build and run kde programs</span>
<span style="color:#898887;">#    based on kdeenv.bat</span>

<span style="color:#644a9b;">cls</span>


<span style="color:#0057ae;">$env</span>:CraftRoot=[System.<span style="color:#644a9b;">IO</span>.<span style="color:#644a9b;">Path</span>]::GetDirectoryName(<span style="color:#0057ae;">$myInvocation</span>.<span style="color:#644a9b;">MyCommand</span>.<span style="color:#644a9b;">Definition</span>)

<span style="color:#0057ae;">$CRAFT_ARGUMENTS</span> = <span style="color:#0057ae;">$args</span>

&amp;{
[version]<span style="color:#0057ae;">$minPythonVersion</span> = 3.<span style="color:#644a9b;">6</span>

<span style="font-weight:bold;">function</span> findPython([<span style="color:#0057ae;">string</span>] <span style="color:#0057ae;">$name</span>)
{
    <span style="color:#0057ae;">$py</span> = (<span style="color:#644a9b;">Get-Command</span> <span style="color:#0057ae;">$name</span> -ErrorAction SilentlyContinue)
    <span style="font-weight:bold;">if</span> (<span style="color:#0057ae;">$py</span> -and (<span style="color:#0057ae;">$py</span> | <span style="color:#644a9b;">Get-Member</span> Version) -and <span style="color:#0057ae;">$py</span>.<span style="color:#644a9b;">Version</span> -ge <span style="color:#0057ae;">$minPythonVersion</span>) {
        <span style="color:#0057ae;">$env</span>:CRAFT_PYTHON=<span style="color:#0057ae;">$py</span>.<span style="color:#644a9b;">Source</span>
    }
}

findPython(<span style="color:#bf0303;">&quot;python3&quot;</span>)
findPython(<span style="color:#bf0303;">&quot;python&quot;</span>)

<span style="font-weight:bold;">function</span> readINI([<span style="color:#0057ae;">string</span>] <span style="color:#0057ae;">$fileName</span>)
{
   <span style="color:#0057ae;">$ini</span> = @{}

  <span style="font-weight:bold;">switch</span> -regex -file <span style="color:#0057ae;">$fileName</span> {
    <span style="color:#bf0303;">&quot;^\[(.+)\]$&quot;</span> {
      <span style="color:#0057ae;">$section</span> = <span style="color:#0057ae;">$matches</span>[1].<span style="color:#644a9b;">Trim</span>()
      <span style="color:#0057ae;">$ini</span>[<span style="color:#0057ae;">$section</span>] = @{}
    }
    <span style="color:#bf0303;">&quot;^\s*([^#].+?)\s*=\s*(.*)&quot;</span> {
      <span style="color:#0057ae;">$name</span>,<span style="color:#0057ae;">$value</span> = <span style="color:#0057ae;">$matches</span>[1..<span style="color:#644a9b;">2</span>]
      <span style="color:#0057ae;">$ini</span>[<span style="color:#0057ae;">$section</span>][<span style="color:#0057ae;">$name</span>] = <span style="color:#0057ae;">$value</span>.<span style="color:#644a9b;">Trim</span>()
    }
  }
  <span style="color:#0057ae;">$ini</span>
}



<span style="font-weight:bold;">if</span>(<span style="color:#644a9b;">test-path</span> -path <span style="color:#0057ae;">$env</span>:CraftRoot\..\etc\kdesettings.<span style="color:#644a9b;">ini</span>)
{
    <span style="color:#0057ae;">$settings</span> = readINI <span style="color:#0057ae;">$env</span>:CraftRoot\..\etc\kdesettings.<span style="color:#644a9b;">ini</span>
}
<span style="font-weight:bold;">else</span>
{
    <span style="color:#644a9b;">Write-Error</span>(<span style="color:#bf0303;">&quot;$env:CraftRoot\..\etc\kdesettings.ini Does not exist&quot;</span>)
    <span style="font-weight:bold;">break</span>
}
<span style="font-weight:bold;">if</span>( <span style="color:#0057ae;">$CRAFT_ARGUMENTS</span>[0] -eq <span style="color:#bf0303;">&quot;--get&quot;</span>)
{
    <span style="color:#644a9b;">Write-Host</span>(<span style="color:#0057ae;">$settings</span>[<span style="color:#0057ae;">$CRAFT_ARGUMENTS</span>[1]][<span style="color:#0057ae;">$CRAFT_ARGUMENTS</span>[2]])
    <span style="font-weight:bold;">break</span>
}


<span style="font-weight:bold;">function</span> prependPATH([<span style="color:#0057ae;">string</span>] <span style="color:#0057ae;">$path</span>)
{
    <span style="color:#0057ae;">$env</span>:PATH=<span style="color:#bf0303;">&quot;$path{0}$env:PATH&quot;</span> -f [IO.<span style="color:#644a9b;">Path</span>]::PathSeparator
}


<span style="font-weight:bold;">if</span>( -Not <span style="color:#0057ae;">$env</span>:CRAFT_PYTHON)
{
    prependPATH <span style="color:#0057ae;">$settings</span>[<span style="color:#bf0303;">&quot;Paths&quot;</span>][<span style="color:#bf0303;">&quot;Python&quot;</span>]
    <span style="color:#0057ae;">$env</span>:CRAFT_PYTHON=[IO.<span style="color:#644a9b;">PATH</span>]::COMBINE(<span style="color:#0057ae;">$settings</span>[<span style="color:#bf0303;">&quot;Paths&quot;</span>][<span style="color:#bf0303;">&quot;Python&quot;</span>], <span style="color:#bf0303;">&quot;python&quot;</span>)
}

(&amp; <span style="color:#0057ae;">$env</span>:CRAFT_PYTHON ([IO.<span style="color:#644a9b;">PATH</span>]::COMBINE(<span style="color:#bf0303;">&quot;$env:CraftRoot&quot;</span>, <span style="color:#bf0303;">&quot;bin&quot;</span>, <span style="color:#bf0303;">&quot;CraftSetupHelper.py&quot;</span>)) <span style="color:#bf0303;">&quot;--setup&quot;</span>) |
<span style="font-weight:bold;">foreach</span> {
  <span style="font-weight:bold;">if</span> (<span style="color:#0057ae;">$_</span> -match <span style="color:#bf0303;">&quot;=&quot;</span>) {
    <span style="color:#0057ae;">$v</span> = <span style="color:#0057ae;">$_</span>.<span style="color:#644a9b;">split</span>(<span style="color:#bf0303;">&quot;=&quot;</span>)
    <span style="color:#644a9b;">set-item</span> -force -path <span style="color:#bf0303;">&quot;ENV:\$($v[0])&quot;</span>  -value <span style="color:#bf0303;">&quot;$($v[1])&quot;</span>
    <span style="color:#898887;">#Write-Host(&quot;$v[0]=$v[1]&quot;)</span>
  }
}

<span style="color:#644a9b;">cd</span> <span style="color:#bf0303;">&quot;$env:KDEROOT&quot;</span>
}


<span style="font-weight:bold;">function</span> Global:craft() {
    <span style="font-weight:bold;">return</span> &amp; <span style="color:#0057ae;">$env</span>:CRAFT_PYTHON ([IO.<span style="color:#644a9b;">PATH</span>]::COMBINE(<span style="color:#bf0303;">&quot;$env:CraftRoot&quot;</span>, <span style="color:#bf0303;">&quot;bin&quot;</span>, <span style="color:#bf0303;">&quot;craft.py&quot;</span>)) <span style="color:#0057ae;">$args</span>
}


<span style="font-weight:bold;">if</span>(<span style="color:#0057ae;">$args</span>.<span style="color:#644a9b;">Length</span> -ne 0)
{
    <span style="color:#644a9b;">invoke-expression</span> -command <span style="color:#bf0303;">&quot;$args&quot;</span>
}
</pre></body></html>
